/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2019-12-10 16:43
 */
package com.yao.common.exception;

import cn.hutool.core.util.StrUtil;
import com.yao.common.enums.IErrorEnum;
import com.yao.common.enums.SysErrorEnum;

/**
 * 业务异常类
 * 
 * @author yaoyuming
 * @date 2019/12/10 16:43
 */
public class BusinessException extends RuntimeException implements IException {

    private int code;

    private Throwable throwable;

    public BusinessException() {
        super();
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
    }

    public BusinessException(Throwable cause) {
        super(cause);
        this.throwable = cause;
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
        this.throwable = cause;
    }

    public BusinessException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.throwable = cause;
    }

    public BusinessException(String template, Object... message) {
        super(StrUtil.format(template, message));
        this.code = SysErrorEnum.ERROR.getErrCode();
    }

    public BusinessException(int code, String template, Object... message) {
        super(StrUtil.format(template, message));
        this.code = code;
    }

    public BusinessException(IErrorEnum errorEnum, String message) {
        super(message);
        this.code = errorEnum.getErrCode();
    }

    public BusinessException(IErrorEnum errorEnum) {
        super(errorEnum.getErrDesc());
        this.code = errorEnum.getErrCode();
    }

    @Override
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public Throwable getThrowable() {
        return throwable;
    }
}